Skip to content

Adds pybids compatability layer to bids2table#69

Merged
kaitj merged 11 commits into
mainfrom
pybids
May 20, 2026
Merged

Adds pybids compatability layer to bids2table#69
kaitj merged 11 commits into
mainfrom
pybids

Conversation

@gkiar
Copy link
Copy Markdown
Collaborator

@gkiar gkiar commented Apr 29, 2026

This is the PR that captures and migrates the development taken place at the nipreps hackathon in this repository. A usage guide showing the compatibility with pybids.BIDSLayout can be found here: https://childmindresearch.github.io/b2t-pybids/.

In particular, the approach taken here:

  • Crawled popular repositories that use pybids to identify the common patterns we should expose and support.
  • Implemented a thin wrapper around the native b2t table structure that provides the same convenience utilities, allowing a drop-in replacement for the vast majority of users.

@gkiar gkiar requested review from kaitj and nx10 April 29, 2026 10:14
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 69.54315% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.86%. Comparing base (c1d67b2) to head (7c6534f).

Files with missing lines Patch % Lines
bids2table/pybids/_layout.py 70.42% 42 Missing ⚠️
bids2table/pybids/_bidsfile.py 65.78% 13 Missing ⚠️
bids2table/pybids/_utils.py 61.53% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #69      +/-   ##
==========================================
- Coverage   95.15%   87.86%   -7.30%     
==========================================
  Files           7       11       +4     
  Lines         495      692     +197     
==========================================
+ Hits          471      608     +137     
- Misses         24       84      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@kaitj kaitj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been mostly playing around with this compatibility layer and haven't had a chance to look too closely at the code yet. It's been a while since I've looked at pybids so I may be misremembering or ignoring functionality.

I think the main divergence that I've seen so far is the ability to query non-standard entities. It's something that has popped up in a few projects with b2t, with different solutions proposed. I think for compatibility (and correct me if I am misremembering how pybids works), it might make sense to flatten the extra_entities into its own columns before / after it has been converted to a dataframe so those entities can be queried directly. This came up in testing indexing the ds000001-fmriprep dataset, where specific transforms couldn't be queried because of from (which may also be a keyword problem) and to entities.

Some minor things that popped up:

  • the entity value type, though I think this is more related to the schema dependency (e.g. sub-01_run-01 is layout.get(subject="01", run=1) instead of layout.get(subject="01", run="01") - probably just me misremembering how pybids works)
  • how or if validation should be performed for a dataset. I can't recall now if there was a reason for not including dataset validation (only entity validation) in b2t.

@adelavega
Copy link
Copy Markdown

adelavega commented Apr 29, 2026

  • Pybids deliberately didn't act as a validator so it did allow for more non-standard but discoverable entities to be used.
  • Yes pybids also normalized run because projects differed on the zero padding.
  • For validation, there is the bids-validator project, so maybe its best to leave the validation to that project?

@nx10
Copy link
Copy Markdown
Collaborator

nx10 commented Apr 29, 2026

I've migrated most of the relevant pybids unit tests over and will add them here tomorrow.

@kaitj
Copy link
Copy Markdown
Contributor

kaitj commented Apr 30, 2026

For validation, there is the bids-validator project, so maybe its best to leave the validation to that project?

💯- I think that makes sense too.

@nx10, I'll open an issue in the relevant repo; it's might be useful for the validator to be a niwrap tool as well.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py60100% 
__main__.py69888%101, 110, 135, 137–138, 164, 168, 172
_entities.py112199%129
_indexing.py212597%150, 159–160, 409, 447
_logging.py31487%30, 37, 39–40
_metadata.py48491%39–40, 66, 71
_pathlib.py170100% 
_version.py110100% 
pybids
   __init__.py40100% 
   _bidsfile.py381365%71–73, 77–79, 83–85, 89–91, 95
   _layout.py1564571%63, 72, 81, 104, 114–115, 118, 140–141, 156–157, 173–174, 177–181, 186, 188–189, 192–193, 228, 233, 241, 322–324, 389–394, 396, 399–404, 406, 462, 482
   _utils.py13561%47–50, 52
TOTAL7178588% 

Tests Skipped Failures Errors Time
100 1 💤 0 ❌ 0 🔥 10.839s ⏱️

kaitj added 4 commits May 14, 2026 13:29
Removed the validate argument from layout initialization. Passing this previously had no effect as it wasn't used anywhere downstream nor did it throw any message about it. With this change, users can still pass the `validate` when initializing BIDSLayout without it doing anything since the method accepts **kwargs
pybids doesn't have a `.df` attribute to BIDSLayout, instead relying on
a `to_df()` method. To avoid breaking this and making it more plug-and-play,
add a method to mimic pybids behaviour and return the attribute value
Previous flattening, via the `.flatten()` method did not flatten the extra entities due to the type of the column. Expected StructType but got MapType instead.

This commit:
  - Adds a method, `_flatten_extra_entities`, that performs the flattening, and adds it to the entity map that is used elsewhere, while moving the root and path columns to the end of the table. The latter is not strictly necessary, but moved it to keep the entity columns together.
  - Removes the TODO note, as "extra_entities" is no longer a column that needs to be considered
Comment thread bids2table/pybids/_layout.py Outdated
@gkiar
Copy link
Copy Markdown
Collaborator Author

gkiar commented May 20, 2026

@kaitj Merged your other PR and addressed other comments; I think we're ready for a final review before merge

Copy link
Copy Markdown
Contributor

@kaitj kaitj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks good to me 🚀

@kaitj kaitj mentioned this pull request May 20, 2026
@kaitj kaitj merged commit e6ab7df into main May 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants